package com.hopu.oa.dao.task;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hopu.oa.entity.management.AoaStatusList;
import com.hopu.oa.entity.task.AoaTaskLogger;
import com.hopu.oa.entity.task.AoaTaskUser;
import com.hopu.oa.entity.task.AoaTasklist;
import com.hopu.oa.entity.task.TongJiWangCeng;
import com.hopu.oa.entity.user.AoaUser;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Secret
 * @create 2021-07-17 上午 09:17
 */
@Mapper
@Repository
public interface TaskuserDao extends BaseMapper<AoaTasklist> {
    List<AoaTasklist> selectTaskList(@Param("userId") Integer userId, @Param("title") String title, @Param("index") int index, @Param("size") int size);

    List<AoaTasklist> selectTaskUser(@Param("userId") Integer userId);


    //查询方法（zty）
    @Select("select * from aoa_task_list")
    List<AoaTasklist> findTasklistAll();


    @Select("select * from aoa_task_logger")
    List<AoaTaskLogger> findTaskloggerAll();

    @Select("select * from aoa_task_list where task_id=#{id}")
    AoaTasklist queryTasklistById(int id);

    @Select("select min(status_id) from  aoa_task_user where task_id = #{id}")
    int querystatusIdById(int id);

    @Select("select * from aoa_user where user_id=#{id}")
    AoaUser queryUserInfoById(int id);

    @Select("select * from aoa_status_list where status_id=#{id}")
    AoaStatusList queryStatusListById(int id);

    @Update("update aoa_task_logger set logger_statusid=#{loggerStatusid},logger_ticking=#{loggerTicking} where task_id=#{taskId}")
    int updateLogger(@Param("loggerStatusid") int loggerStatusid, @Param("loggerTicking") String loggerTicking, @Param("taskId") int taskId);

    @Update("update aoa_task_list set status_id=#{loggerStatusid} where task_id=#{taskId}")
    int updateTask(@Param("loggerStatusid") int loggerStatusid, @Param("taskId") int taskId);

    @Update("update aoa_task_user set status_id=#{loggerStatusid} where task_id=#{taskId} and task_recive_user_id=#{uid}")
    int updateTaskUser(@Param("loggerStatusid") int loggerStatusid, @Param("taskId") int taskId, @Param("uid") int uid);

    @Update("update aoa_task_user set status_id=#{loggerStatusid} where task_id=#{taskId} ")
    int updateTaskUserByTaskId(@Param("loggerStatusid") int loggerStatusid, @Param("taskId") int taskId);


    @Select("select * from aoa_task_list where task_id=#{taskId}")
    AoaTasklist getTaskById(Integer taskId);

    @Delete("delete from aoa_task_list where task_id=#{Id}")
    int myshanchu(int id);

    @Delete("delete from aoa_task_logger where task_id=#{Id}")
    int loggershanchu(int id);

    @Delete("delete from aoa_task_user where task_id=#{Id}")
    int usershanchu(int id);

    @Select("SELECT task_recive_user_id uId,COUNT(*) size FROM aoa_task_user WHERE status_id=7 GROUP BY task_recive_user_id ORDER BY COUNT(*) DESC LIMIT 0,5")
    List<TongJiWangCeng> selectTongJi();
}

